CREATE DATABASE QLSieuThi
GO

USE [QLSieuThi]
GO


SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Doanhthu](
	[MaSP] [varchar](10) NOT NULL,
	[Mahoadon] [varchar](10) NOT NULL,
	[Ngay] [int] NOT NULL,
	[Tongthanhtien] [int] NOT NULL,
 CONSTRAINT [PK_Doanhthu] PRIMARY KEY CLUSTERED 
(
	[MaSP] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

ALTER TABLE [dbo].[Doanhthu]  WITH CHECK ADD  CONSTRAINT [FK_Doanhthu_Hoadon] FOREIGN KEY([Mahoadon])
REFERENCES [dbo].[Hoadon] ([Mahoadon])
GO

ALTER TABLE [dbo].[Doanhthu] CHECK CONSTRAINT [FK_Doanhthu_Hoadon]
GO
CREATE TABLE [dbo].[Hoadon](
	[Mahoadon] [varchar](10) NOT NULL,
	[MaNV] [varchar](10) NOT NULL,
	[Makhachhang] [varchar](10) NOT NULL,
	[Ngay] [int] NOT NULL,
	[MaSP] [varchar](10) NOT NULL,
	[TenSP] [nvarchar](30) NOT NULL,
	[Soluong] [int] NOT NULL,
	[Dongia] [int] NOT NULL,
	[Thanhtien] [int] NOT NULL,
	[Discount] [int] NULL,
 CONSTRAINT [PK_Hoadon] PRIMARY KEY CLUSTERED 
(
	[Mahoadon] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO
ALTER TABLE [dbo].[Hoadon]  WITH CHECK ADD  CONSTRAINT [FK_Hoadon_Khachhang] FOREIGN KEY([Makhachhang])
REFERENCES [dbo].[Khachhang] ([Makhachhang])
GO

ALTER TABLE [dbo].[Hoadon] CHECK CONSTRAINT [FK_Hoadon_Khachhang]
GO

ALTER TABLE [dbo].[Hoadon]  WITH CHECK ADD  CONSTRAINT [FK_Hoadon_Nhanvien] FOREIGN KEY([MaNV])
REFERENCES [dbo].[Nhanvien] ([MaNV])
GO

ALTER TABLE [dbo].[Hoadon] CHECK CONSTRAINT [FK_Hoadon_Nhanvien]
GO

CREATE TABLE [dbo].[Khachhang](
	[Makhachhang] [varchar](10) NOT NULL,
	[HotenKH] [nvarchar](30) NULL,
	[Mathe] [varchar](10) NULL,
	[Diachi] [nvarchar](30) NULL,
	[Dienthoai] [int] NULL,
 CONSTRAINT [PK_Khachhang] PRIMARY KEY CLUSTERED 
(
	[Makhachhang] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO
ALTER TABLE [dbo].[Khachhang]  WITH CHECK ADD  CONSTRAINT [FK_Khachhang_LoaiKH] FOREIGN KEY([Mathe])
REFERENCES [dbo].[LoaiKH] ([Mathe])
GO

ALTER TABLE [dbo].[Khachhang] CHECK CONSTRAINT [FK_Khachhang_LoaiKH]
GO

CREATE TABLE [dbo].[Khuyenmai](
	[MaSP] [varchar](10) NOT NULL,
	[ThoigianKM] [int] NULL,
	[Discount] [int] NULL,
 CONSTRAINT [PK_Khuyenmai] PRIMARY KEY CLUSTERED 
(
	[MaSP] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[LoaiKH](
	[Mathe] [varchar](10) NOT NULL,
	[TenloaiKH] [nvarchar](30) NULL,
 CONSTRAINT [PK_LoaiKH] PRIMARY KEY CLUSTERED 
(
	[Mathe] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[LoaiNV](
	[MaloaiNV] [varchar](10) NOT NULL,
	[TenloaiNV] [nvarchar](30) NOT NULL,
 CONSTRAINT [PK_LoaiNV] PRIMARY KEY CLUSTERED 
(
	[MaloaiNV] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Nhanvien](
	[MaNV] [varchar](10) NOT NULL,
	[Hoten] [nvarchar](30) NOT NULL,
	[MaloaiNV] [varchar](10) NOT NULL,
	[Diachi] [nvarchar](30) NOT NULL,
	[Dienthoai] [int] NOT NULL,
	[Ngaysinh] [int] NOT NULL,
	[Gioitinh] [nvarchar](10) NOT NULL,
	[Mataikhoan] [varchar](10) NOT NULL,
 CONSTRAINT [PK_Nhanvien] PRIMARY KEY CLUSTERED 
(
	[MaNV] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[Nhanvien]  WITH CHECK ADD  CONSTRAINT [FK_Nhanvien_LoaiNV] FOREIGN KEY([MaloaiNV])
REFERENCES [dbo].[LoaiNV] ([MaloaiNV])
GO

ALTER TABLE [dbo].[Nhanvien] CHECK CONSTRAINT [FK_Nhanvien_LoaiNV]
GO

ALTER TABLE [dbo].[Nhanvien]  WITH CHECK ADD  CONSTRAINT [FK_Nhanvien_QuanlyTK] FOREIGN KEY([Mataikhoan])
REFERENCES [dbo].[QuanlyTK] ([Mataikhoan])
GO

ALTER TABLE [dbo].[Nhanvien] CHECK CONSTRAINT [FK_Nhanvien_QuanlyTK]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Nhap](
	[MaSP] [varchar](10) NOT NULL,
	[MaNV] [varchar](10) NOT NULL,
	[TenSP] [nvarchar](30) NULL,
	[Soluongnhap] [int] NULL,
 CONSTRAINT [PK_Nhap] PRIMARY KEY CLUSTERED 
(
	[MaSP] ASC,
	[MaNV] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[Nhap]  WITH CHECK ADD  CONSTRAINT [FK_Nhap_Nhanvien1] FOREIGN KEY([MaNV])
REFERENCES [dbo].[Nhanvien] ([MaNV])
GO

ALTER TABLE [dbo].[Nhap] CHECK CONSTRAINT [FK_Nhap_Nhanvien1]
GO

ALTER TABLE [dbo].[Nhap]  WITH CHECK ADD  CONSTRAINT [FK_Nhap_QuanlySP] FOREIGN KEY([MaSP])
REFERENCES [dbo].[QuanlySP] ([MaSP])
GO

ALTER TABLE [dbo].[Nhap] CHECK CONSTRAINT [FK_Nhap_QuanlySP]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[QuanlySP](
	[MaSP] [varchar](10) NOT NULL,
	[TenSP] [nvarchar](30) NOT NULL,
	[Dongia] [int] NULL,
	[Soluongtonkho] [int] NULL,
	[Soluongcontaiquay] [int] NULL,
	[Mucquydinhquay] [int] NULL,
	[Mucquydinhkho] [int] NULL,
 CONSTRAINT [PK_QuanlySP] PRIMARY KEY CLUSTERED 
(
	[MaSP] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[QuanlySP]  WITH CHECK ADD  CONSTRAINT [FK_QuanlySP_Doanhthu] FOREIGN KEY([MaSP])
REFERENCES [dbo].[Doanhthu] ([MaSP])
GO

ALTER TABLE [dbo].[QuanlySP] CHECK CONSTRAINT [FK_QuanlySP_Doanhthu]
GO

ALTER TABLE [dbo].[QuanlySP]  WITH CHECK ADD  CONSTRAINT [FK_QuanlySP_Khuyenmai] FOREIGN KEY([MaSP])
REFERENCES [dbo].[Khuyenmai] ([MaSP])
GO

ALTER TABLE [dbo].[QuanlySP] CHECK CONSTRAINT [FK_QuanlySP_Khuyenmai]
GO

ALTER TABLE [dbo].[QuanlySP]  WITH CHECK ADD  CONSTRAINT [FK_QuanlySP_Thongke] FOREIGN KEY([MaSP])
REFERENCES [dbo].[Thongke] ([MaSP])
GO

ALTER TABLE [dbo].[QuanlySP] CHECK CONSTRAINT [FK_QuanlySP_Thongke]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[QuanlyTK](
	[Mataikhoan] [varchar](10) NOT NULL,
	[TenloaiTK] [nvarchar](30) NOT NULL,
 CONSTRAINT [PK_QuanlyTK] PRIMARY KEY CLUSTERED 
(
	[Mataikhoan] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Thongke](
	[MaSP] [varchar](10) NOT NULL,
	[TenSP] [nvarchar](30) NULL,
	[Soluongtonkho] [int] NULL,
	[Soluongcontaiquay] [int] NULL,
 CONSTRAINT [PK_Thongke] PRIMARY KEY CLUSTERED 
(
	[MaSP] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO


